package cz.possoft.generic.utils;

/**
  * Trida obsahuje vseobecne konstanty a utility
  * 
  * @author mara
  */
public class GenericUtils {
	
	// Konstanty barev figurek
	public static final int COLOR_NEUTRAL = 0;
	public static final int COLOR_BLACK = 1;
	public static final int COLOR_WHITE = 2;
	
    public static final int PORT = 2610;
    public static final String CGI_SCRIPT_TO_HTTP_REQUEST_ADDRESS = "/~xposolda/net/MyServer5.cgi";	
	
    // vraci absolutni hodnotu
    public static int abs(int x) {
        if (x >= 0) {
            return x;
        } else {
            return -x;
        }
    }
    
    // vraci jmeno vyzivatele z vyzivaci hlasky
    // pr. z 'VYZVAL: aaa_Chess' vraci 'aaa'
    // pouzito ve vlaknech ConnectThread a ChessServerSocket
    public static String getVyzivatelName(String message) {
        if (message.length() > 8) {
        	if (message.indexOf("_") > 8) {
        		return message.substring(8, message.indexOf("_"));
        	}
            return message.substring(8);
        }
        return "";
    }
    
    // vraci klic nazvu hry z vyzivaci hlasky
    // pr. z 'VYZVAL: aaa_Chess' vraci 'Chess'
    // pouzito ve vlaknech ConnectThread a ChessServerSocket
    public static String getGameKey(String message) {
        if (message.length() > 8) {
        	if (message.indexOf("_") > 8) {
        		return message.substring(message.indexOf("_") + 1);
        	}            
        }
        return "";
    }        

}
